﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System8Equations;
using System.Linq;

namespace t_System8Equations
{
    [TestClass]
    public class t_UniformS8Variable
    {
        [TestMethod]
        public void TestCtor()
        {
            UniformS8Variable uv = new UniformS8Variable(0.0);
        }

        [TestMethod]
        public void TestRandomGeneration()
        {
            UniformS8Variable uv = new UniformS8Variable(15.0) { Path = "n.Totalvalue", MaxValue = 20, MinValue = 10.1 };

            var all = from n in uv
                      select n;

            var firstSet = all.Take(1000);
            var bad = from n in firstSet
                      where n < 10.1 || n > 30
                      select n;

            Assert.AreEqual(0, bad.Count(), "Expected no numbers outside the boundary");
        }

        [TestMethod]
        public void TestToString()
        {
            UniformS8Variable uv = new UniformS8Variable(15.0) { Path = "n/TotalValue", MaxValue = 20, MinValue = 10.1 };
            Assert.AreEqual("n.Total Norm(10.1-20)", uv.ToString(), "Incorrect translation");
        }

        [TestMethod]
        public void TestUpdate()
        {
            UniformS8Variable uv = new UniformS8Variable(20.0) { Path = "n.TotalValue", MaxValue = 22, MinValue = 18 };
            uv.Update(20);
            Assert.AreEqual(22, uv.MaxValue, "Max should not have changed");
            Assert.AreEqual(18, uv.MinValue, "Min should not have changed!");

            uv.Update(30);
            Assert.AreEqual(33, uv.MaxValue, "Max should have updated");
            Assert.AreEqual(27, uv.MinValue, "Min should have updated");
        }
    }
}